package scau.erps.view.dashboard;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;

import scau.erps.app.Erps;
import scau.erps.service.OrderSetService;
import scau.erps.service.impl.OrderSetServiceImpl;

/**
 * 区域预测3D柱状图
 * @author DCJ
 *
 */
public class RegionChart {
	public static JFreeChart getChart() {
		JFreeChart chart = createChart(createDataset());
		return chart;
	}

	/**
	 * 数据
	 */
	public static CategoryDataset createDataset() {		
		String[] rowKeys = { "本地", "区域", "国内","亚洲","国际" };// 行标志
		String[] columnKeys = { "Y1", "Y2", "Y3", "Y4", "Y5", "Y6","Y7" };// 列标志
		OrderSetService orderSetService=Erps.getIocInstance().get(OrderSetServiceImpl.class);
		double[][] total = new double[5][7];
		for (int i = 0; i < rowKeys.length; i++) {
			for (int j = 0; j < columnKeys.length; j++) {
				total[i][j]= orderSetService.getTotalByMarketAndYear(rowKeys[i], columnKeys[j]);				
			}			
		}
		CategoryDataset linedataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, total); // 建立数据集
		return linedataset;
	}

	/**
	 * 绘柱状图
	 */
	public static JFreeChart createChart(CategoryDataset dataset) {
		//createChart3D参数依次为：标题，横轴名称，纵轴名称，数据，方向，显示图例，工具，超链接)
		JFreeChart chart = ChartFactory.createBarChart3D("区域-年份市场预测", "区域","市场产品数量(个)",dataset,PlotOrientation.VERTICAL,true,	false, false);
		return chart;
	}
}
